package cn.sys.service.impl;

import cn.sys.domain.Log;
import cn.sys.mapper.LogMapper;
import cn.sys.service.LogService;
import cn.sys.utils.DataGridView;
import cn.sys.vo.LogVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mxb
 * @version 1.0
 * @date 2019/11/1 9:18
 */
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    /**
     * 查询所有
     * @param logInfoVo
     * @return
     */
    @Override
    public DataGridView queryAllLoginInfo(LogVo logInfoVo) {
        Page<Object> page = PageHelper.startPage(logInfoVo.getPage(), logInfoVo.getLimit());
        List<Log> data = this.logMapper.queryAllLogInfo(logInfoVo);

        return new DataGridView(page.getTotal(), data);
    }

    /**
     * 添加日志
     * @param logInfoVo
     */
    @Override
    public void addLog(LogVo logInfoVo) {
        this.logMapper.insertSelective(logInfoVo);
    }

    /**
     * 删除日志
     * @param logid
     */
    @Override
    public void deleteLogInfo(Integer logid) {
        this.logMapper.deleteByPrimaryKey(logid);
    }

    /**
     * 批量删除日志
     * @param ids
     */
    @Override
    public void deleteBatchLog(Integer[] ids) {
        for (Integer id : ids) {
            this.logMapper.deleteByPrimaryKey(id);
        }
    }
}
